package exercisesII;

import java.util.*;

public class Exercise4 {

	// Read 10 numbers and perform some tasks

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		// Declare the array to store the values
		double [] nums;
		nums = new double[10];
		
		// Ask the user to enter the values
		int i;		
		for (i=0; i<=9; i++) {	
			System.out.print("Please enter a positive value for number " + (i+1) + ": ");
			nums[i] = sc.nextDouble();
		}
		System.out.println("------------------");
		
		// A: Add all the numbers
		double addition = 0;
		for (i=0; i<=9; i++) {
			addition = addition + nums[i];
		}
		System.out.println("The result of adding the numbers you entered is " + addition);
		
		// B:  Arithmetic mean of the numbers
		double mean;
		mean = addition / 10;
		System.out.println("The arithmetic mean of the numbers you entered is " + mean);
		
		// C:  Largest number
		// For this, I'll use Math.max to compare values two by two
		double largest = nums[0];
		for (i=0; i<=9; i++) {		
			largest = Math.max(largest, nums[i]);
		}
		System.out.println("The largest number is " + largest);
		
		// D: Smallest number
		// For this, I'll use Math.min to compare values two by two
		double smallest = nums[0];
		for (i=9; i>=0; i--) {
			smallest = Math.min(smallest, nums[i]);
		}
		System.out.println("The smallest number is " + smallest);
		

	}

}
